package com.uxhao.staservice.schedule;

import com.uxhao.staservice.service.StatisticsDailyService;
import com.uxhao.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务 [生成统计数据]
 * @author uxhao
 * @date 2021/1/25 23:52
 */
@Component
public class ScheduledTask {
    @Autowired
    private StatisticsDailyService staService;

    /**
     * cron 在每天凌晨1点，把前一天数据进行查询添加
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task1(){
        staService.createStatisticsByDay(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)));
    }

}
